﻿
@{
    Layout = null;
}

<div>
    <div class="col-3 pr-0" style="display: none">
        <label id="SAMPLE-SetSkipWorkflow-Indicate">@ViewData["SetSampleLogin"]</label>
        <label id="SAMPLE-SetSkipWorkflow-SDId">@ViewData["SampleDefefinitionId"]</label> @*如果设置的是登录样品，这个ID就是登录样品的ID*@
        <label id="SAMPLE-SetSkipWorkflow-Parent-ModalID">@ViewData["ModalID"]</label>
    </div>
</div>
<div class="input-group">
    <div class="col-12 pr-0 pl-0">
        <span class="input-group-text font-rfs-modal border-radius-noright">设置步骤</span>
    </div>
</div>
<div class="table-responsive-sm modal-table-shadow p-0 bg-white rounded col-md-12 pre-scrollable" style="height: 60vh;">
    <table id="SAMPLE-SetSkipWorkflow-List" class="table table-striped table-bordered-modal table-sm">
        <thead>
            <tr>
                <th>ID</th>
                <th>跳过</th>
                <th>步骤名称</th>
            </tr>
        </thead>
        <tbody style="font-size: calc(0.6em + 0.1vw) !important"></tbody>
    </table>
</div>
<div class="text-right" style="padding-top: 5px;">
    <button id="SAMPLE-SetSkipWorkflow-confirm" type="button" class="btn btn-primary font-rfs-modal">确定</button>
    <button id="SAMPLE-SetSkipWorkflow-cancel" type="button" class="btn btn-info font-rfs-modal">取消</button>
</div>

<script>

    $(document).ready(function () {
        if ($("#SAMPLE-SetSkipWorkflow-Indicate").html() == "False") {
            LoadSampleDefinitionStepSequence();
        } else {
            LoadSampleLoginStepSequence();
        }
    });

    function LoadSampleDefinitionStepSequence() {
        var columns = [{ field: "id", visible: false }, { field: "skip", width: "10%", align: "center", checkbox: true },
                    { field: "stepName" }];

        $('#SAMPLE-SetSkipWorkflow-List').bootstrapTable('destroy'); // 这行代码必须加，否则数据无法刷新
        $('#SAMPLE-SetSkipWorkflow-List').bootstrapTable({
            method: 'post',
            url: "GetSampleDefinitionWorkflowStepSequence",
            dataType: "json",  // 服务器端返回值类型
            contentType: "application/x-www-form-urlencoded; charset=UTF-8", // 如果是 POST 请求，这个属性必须加
            queryParams: function (params) {
                var data = {
                    SampleDefefinitionId: $("#SAMPLE-SetSkipWorkflow-SDId").html(),
                };
                return data;
            }, //参数
            queryParamsType: "search", //参数格式,发送标准的RESTFul类型的参数请求

            uniqueId: "id",          // 设置主键
            locale: "zh-CN",
            columns: columns,          // 加载列定义, 注意！这个地方绑定的列名称开头大写字母会全部变成小写。

            selectItemName: "skip", // 跳过指示
            clickToSelect: true, // 相应单击，自动选中此行
            checkboxHeader: false, // 标题行显示全选按钮

            onClickRow: function (row, $element, field) {
                //$("#SAMPLE-SetSkipWorkflow-List").find("tbody").find("tr").each(function () {
                //    $(this).removeClass('changeblueColor');
                //});
                //$element.addClass("changeblueColor");
                SelectSpec_specId = row.id;
            },
            silent: true,  //刷新事件必须设置
            formatLoadingMessage: function () {
                return "请稍等，正在加载中...";
            },
            formatNoMatches: function () {  //没有匹配的结果
                $('.fixed-table-toolbar').css("height", "0px"); /* 隐藏表格上的工具栏 */
                return "没有找到样品定义，或该样品关联的流程已被删除！";
            },
            onLoadSuccess: function (data) {   // 数据加载成功后触发该事件
                $('.fixed-table-toolbar').css("height", "0px"); /* 隐藏表格上的工具栏 */
                $('td label').css("margin-bottom", "0px"); // 设置数据行选择控件的样式
            },
            onLoadError: function (data) {
                $('#SAMPLE-SetSkipWorkflow-List').bootstrapTable('removeAll');
            }
        });
    }

    function LoadSampleLoginStepSequence() {
        var columns = [{ field: "id", visible: false }, { field: "skip", width: "10%", align: "center", checkbox: true },
        { field: "stepName" }];

        $('#SAMPLE-SetSkipWorkflow-List').bootstrapTable('destroy'); // 这行代码必须加，否则数据无法刷新
        $('#SAMPLE-SetSkipWorkflow-List').bootstrapTable({
            method: 'post',
            url: "GetSampleLoginWorkflowStepSequence",
            dataType: "json",  // 服务器端返回值类型
            contentType: "application/x-www-form-urlencoded; charset=UTF-8", // 如果是 POST 请求，这个属性必须加
            queryParams: function (params) {
                var data = {
                    SampleLoginId: $("#SAMPLE-SetSkipWorkflow-SDId").html(),
                };
                return data;
            }, //参数
            queryParamsType: "search", //参数格式,发送标准的RESTFul类型的参数请求

            uniqueId: "id",          // 设置主键
            locale: "zh-CN",
            columns: columns,          // 加载列定义, 注意！这个地方绑定的列名称开头大写字母会全部变成小写。

            selectItemName: "skip", // 跳过指示
            clickToSelect: true, // 相应单击，自动选中此行
            checkboxHeader: false, // 标题行显示全选按钮

            onClickRow: function (row, $element, field) {
                //$("#SAMPLE-SetSkipWorkflow-List").find("tbody").find("tr").each(function () {
                //    $(this).removeClass('changeblueColor');
                //});
                //$element.addClass("changeblueColor");
                SelectSpec_specId = row.id;
            },
            silent: true,  //刷新事件必须设置
            formatLoadingMessage: function () {
                return "请稍等，正在加载中...";
            },
            formatNoMatches: function () {  //没有匹配的结果
                $('.fixed-table-toolbar').css("height", "0px"); /* 隐藏表格上的工具栏 */
                return "没有找到样品，或该样品关联的流程已被删除！";
            },
            onLoadSuccess: function (data) {   // 数据加载成功后触发该事件
                $('.fixed-table-toolbar').css("height", "0px"); /* 隐藏表格上的工具栏 */
                $('td label').css("margin-bottom", "0px"); // 设置数据行选择控件的样式
            },
            onLoadError: function (data) {
                $('#SAMPLE-SetSkipWorkflow-List').bootstrapTable('removeAll');
            }
        });
    }

    $("#SAMPLE-SetSkipWorkflow-cancel").click(function (event) {
        var modalID = $("#SAMPLE-SetSkipWorkflow-Parent-ModalID").html();
        $("#" + modalID).modal('hide');
    });

    $("#SAMPLE-SetSkipWorkflow-confirm").click(function () {
        var st = SampleLoginGetSelectItems();

        if ($("#SAMPLE-SetSkipWorkflow-Indicate").html() == "False") {
            $.post("UpdateSampleDefenitionSkipSequence", {
                SampleDefefinitionId: $("#SAMPLE-SetSkipWorkflow-SDId").html(),
                SkipSequence: st
            }, function (data) {
                if (data.indexOf("成功") >= 0) {
                    $("#SAMPLE-SetSkipWorkflow-cancel").click();
                } else {
                    alert(data);
                }
            });
        } else {
            $.post("UpdateSampleLoginSkipSequence", {
                SampleLoginId: $("#SAMPLE-SetSkipWorkflow-SDId").html(),
                SkipSequence: st
            }, function (data) {
                if (data.indexOf("成功") >= 0) {
                    $("#SAMPLE-SetSkipWorkflow-cancel").click();
                } else {
                    alert(data);
                }
            });
        }
    });

    function SampleLoginGetSelectItems() {
        var rows = $('#SAMPLE-SetSkipWorkflow-List').bootstrapTable('getSelections');
        if (rows.length == 0) {
            return;
        } else {
            var arrays = new Array();
            $(rows).each(function () {
                arrays.push(this.id);
            })

            var ids = arrays.join(',');
            return ids;
        }
    }

</script>
